from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap={
            "platformName": "Android",
            "appium:deviceName": "emulator-5554",
            "appium:automationName": "uiautomator2",
            "appium:appPackage": "com.kongfz.app",
            "appium:appActivity": ".home.mvvm.homepage.HomeActivity",
            "appium:noReset": True
        }
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        #隐式等待
        self.driver.implicitly_wait(20)
        #执行方式
    def find_ele(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    #显示等待
    def xianshi(self,loc):
        ele=WebDriverWait(self.driver,30).until(EC.element_to_be_clickable(loc))
        return ele
    #关闭
    def guanbi(self):
        self.driver.quit()
    #轻敲
    def dian(self,a,b,c):
        self.driver.tap([(a,b)],c)
    #滑动
    def hua(self,a,b,c,d):
        self.driver.swipe(a,b,c,d)
    #截屏
    def jieping(self,name):
        self.driver.save_screenshot(name)
    #键盘
    def home(self):
        self.driver.press_keycode(3)

    def back(self):
        self.driver.press_keycode(4)